package com.IntelligenceInsight.Myth.mapper;

import com.IntelligenceInsight.Myth.model.Job;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
@Repository
public interface JobMapper {
    @Select("SELECT * FROM job WHERE owner=#{owner} ORDER BY id DESC")
    List<Job> JobListByOwner(@Param("owner") String owner);

    @Select("SELECT * FROM job ORDER BY timeCreate DESC LIMIT #{page},#{limit}")
    List<Job> JobListAll(@Param("page") int page, @Param("limit") int limit);

    @Select("SELECT COUNT(*) FROM job")
    int JobListAllCount();

    @Select("SELECT * FROM job WHERE uuid=#{uuid}")
    Job JobByUuid(@Param("uuid") String uuid);

    @Select("SELECT * FROM job WHERE name=#{name}")
    Job JobByName(@Param("name") String name);

    @Select("SELECT * FROM job WHERE model=#{model} and id in (select Max(id) from job group by dataset)")
    List<Job> JobByModel(@Param("model")  String model);

//    @Insert("INSERT INTO job(uuid, name, model, owner, parameters, result) VALUES"+"(#{uuid}, #{name}, #{model}, #{owner}, #{parameters}, #{result})")
//    int JobAdd(@Param("uuid") String uuid, @Param("name") String name, @Param("model") String model, @Param("owner") String owner, @Param("parameters") String parameters, @Param("result") String result);

    @Insert("INSERT INTO job(model, dataset, params) VALUES"+"(#{model}, #{dataset}, #{params})")
    int JobAdd(@Param("model") String model, @Param("dataset") String dataset, @Param("params") String params);

    @Update("UPDATE job set state=#{uuid}, result=#{state} WHERE uuid=#{uuid}")
    int JobStateChange(@Param("uuid") String uuid, @Param("state")  String state, @Param("result")  String result);

    @Delete("DELETE FROM job WHERE uuid=#{uuid}")
    int JobDelete(@Param("uuid") String uuid);

}
